package com.smartwebx.ha.web.util.kml;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.URL;
import java.net.URLConnection;
import java.util.List;
import java.util.Map;

public class HttpRequest {
	public static String sendGet(String url, String param) {
        String result = "";
        BufferedReader in = null;
        try {
            String urlNameString = url + "?" + param;
            URL realUrl = new URL(urlNameString);
           
            URLConnection connection = realUrl.openConnection();
            
            connection.setRequestProperty("accept", "*/*");
            connection.setRequestProperty("connection", "Keep-Alive");
            connection.setRequestProperty("user-agent",
                    "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
            
            connection.connect();
         
            Map<String, List<String>> map = connection.getHeaderFields();
           
            for (String key : map.keySet()) {
                System.out.println(key + "--->" + map.get(key));
            }
           
            in = new BufferedReader(new InputStreamReader(
                    connection.getInputStream()));
            String line;
            while ((line = in.readLine()) != null) {
                result += line;
            }
        } catch (Exception e) {
            System.out.println("异常" + e);
            e.printStackTrace();
        }
        finally {
            try {
                if (in != null) {
                    in.close();
                }
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
        return result;
    }

    public static String sendPost(String url, String param) {
        PrintWriter out = null;
        BufferedReader in = null;
        String result = "";
        try {
            URL realUrl = new URL(url);
            URLConnection conn = realUrl.openConnection();
            conn.setRequestProperty("accept", "*/*");
            conn.setRequestProperty("connection", "Keep-Alive");
            conn.setRequestProperty("user-agent",
                    "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
            conn.setDoOutput(true);
            conn.setDoInput(true);
            out = new PrintWriter(conn.getOutputStream());
            out.print(param);
            out.flush();
            in = new BufferedReader(
                    new InputStreamReader(conn.getInputStream()));
            String line;
            while ((line = in.readLine()) != null) {
                result += line;
            }
        } catch (Exception e) {
            System.out.println("异常"+e);
            e.printStackTrace();
        }
        finally{
            try{
                if(out!=null){
                    out.close();
                }
                if(in!=null){
                    in.close();
                }
            }
            catch(IOException ex){
                ex.printStackTrace();
            }
        }
        return result;
    }    
    
    public static void main(String[] args) {
    	String url="http://10.32.36.36/hgp/devapi/JiangSuRealTimeRainContour";
    	//预约信息推送
    	String pa ="borderId=320000&edate=201512188&sdate=201512178&rainLevel=A:10,25,50,100,150,200&rainData=117.684778,33.948944,871.5,大寺,509B4440|118.876876,34.983596,830.0,汪子头,51321300|119.485931,34.243698,796.5,小潮河闸,51103000|119.0333,34.8333,765.5,朱堵集,51321750|119.1,34.9833,754.5,朱汪,51320850|118.874444,34.9225,740.0,夹谷山,51131650|119.168529,35.051921,740.0,石桥,51320600|119.4333,34.7833,734.0,西连岛,51321950|118.878421,35.030418,730.5,黑林,51300500|118.836639,34.916472,718.5,马山,513B2140|118.855833,34.91425,711.5,金牛山,513B2100|118.851861,34.902556,711.5,抗日山,513B2180|118.973178,34.941392,705.6,小塔山水库,51300601|118.882417,34.987694,701.0,北康邑,513B1660|118.866056,35.028139,700.5,沟屋,513B1560|119.434415,34.201372,699.5,东山岔,51109650|117.88,34.12,697.0,古邳,51235200|119.132137,34.828318,697.0,青口,51321500|118.881111,34.938056,693.5,狼山,513B2020|118.863222,34.918,693.0,孟良,513B2120|118.890444,35.033,690.0,埠地,513B1460|118.865417,34.992667,689.0,介河,513B1600|118.8667,34.8667,686.0,班庄,51321550|118.8455,34.922917,686.0,吴沟,513B2080|118.869222,35.006917,682.5,河西,513B1620|118.803889,34.876694,679.5,新西,511B7000|118.871806,34.936194,679.0,祝其山,513B2040|118.86925,34.95275,675.0,接庄,513B2000|118.865889,35.018056,674.5,申疃,513B1540|118.926389,35.01425,670.0,大树,513B1520|118.964417,34.983917,664.5,吴山前,513B1640|117.977806,34.517917,662.5,艾山,512B9360|118.935806,34.995611,662.0,西石沟,513B1580|118.338694,34.254611,657.0,山庄,511B8660|119.048538,34.698013,656.0,岳庄,51131900|118.878139,34.922889,654.0,夹谷山,513B2060|118.821889,34.890806,653.5,红领巾,513B2200|119.613,31.1726,652.6000000000001,大涧,63124400|118.5833,34.6,644.5,双店,51133100|121.268109,31.503666,643.5,浏河闸(上),63205050|118.886111,34.898361,643.5,车辐山,513B2160|118.921028,35.044556,642.5,芦草沟,513B1420|118.93275,35.008667,640.5,范良庄,513B1500|119.28749,34.208679,637.5999999999999,盐河南闸,51102800|118.314194,34.244889,636.0,新湖,511B8720|118.424,34.265417,630.5,新庄,511B8280|117.9266,34.5234,629.0000000000001,林子,51209500|119.03,34.21,628.0,吴集,51126600|119.161528,35.09625,628.0,宋岭,513B1080|119.045791,35.034213,626.5,八条路水库,51112700|118.562889,34.519028,626.5,八一,513B2260|118.9635,34.992389,625.5,楼山,513B1400|118.85,34.3,624.5,朱贵庄,51126900|118.392361,34.233417,622.5,宋山,511B8300|118.8628,34.768973,621.8,石梁河水库,51112101|118.628311,34.594573,621.1,昌黎水库,51115650|119.126306,35.067389,619.0,狼窝,513B1240|118.909917,34.922028,618.5,管葛埠,513B1900|118.903611,34.898556,618.5,万桥1号(2),513B1970|118.853306,34.878667,618.5,三八,513B2240|118.34,34.235167,617.5,陆庄,511B8600|118.289028,34.167139,617.0,龙潭,511B8540|119.2,34.7333,616.0,范河闸,51321850|118.913528,34.924694,614.5,郭葛埠,513B1920|119.146213,34.620636,609.5,临洪,51113800|118.897694,34.894889,608.5,万桥2号(2),513B1990|118.94775,35.018389,608.0,石门沟,513B1360|119.095361,35.039833,606.0,怀仁山,513B1340|118.842,34.875361,606.0,五四,513B2280|118.303917,34.239278,605.0,高林（1),511B8500|119.150306,35.072556,604.5,姜林,513B1120|118.9,34.35,604.0,青伊湖,51132800|121.077478,31.304289,603.5,花桥,63424400|118.949139,35.033389,603.5,马旦头,513B1440|118.284222,34.276194,603.0,小冲,511B8700|119.253158,34.298629,602.5,灌云,51128800|118.420111,34.2835,602.5,小何,511B8420|118.35,34.366667,601.9000000000001,新安,51113400|118.457,34.270889,601.5,白石,511B8400|119.172722,35.098722,601.5,霍官庄,513B1040|119.123472,35.026056,601.5,王集,513B1220|118.983444,34.9885,601.5,车赤涧,513B1680|121.8137,31.7543,601.0,希士,51030900|119.566111,34.2075,599.8,响水口,51109900|118.999306,34.993417,599.5,顾赤涧,513B1700|121.820982,31.850355,599.1000000000001,向阳,62730950|119.123083,35.063111,598.5,竹园,513B1260|118.454556,34.331667,597.0,石涧,511B8440|119.09025,35.050417,596.5,临马疃,513B1320|118.48,34.51,595.5,桃林,51126250|118.972611,35.034611,595.0,西陡岭,513B1780|118.834417,34.873139,595.0,五一,513B2300|119.133361,35.057639,593.5,大庄1号,513B1200|117.969646,34.62558,592.6,四户,51227650|120.805914,31.378244,591.5,唯亭,63225700|119.137306,35.068639,591.0,大庄3号,513B1160|119.822186,34.396591,591.0,陈港,51129150|119.159111,35.069417,590.0,石桥,513B1140|118.569194,34.6235,589.0,狼墩,511B7520|119.006889,34.997278,589.0,万赤涧,513B1720|118.903611,34.898556,587.5,万桥1号(1),513B1960|119.229194,35.109861,587.0,西吉荡,513B1000|118.891833,34.883944,587.0,演马场,513B2220|119.157806,35.087306,584.5,姜陡沟,513B1100|119.019972,34.999694,584.5,小山子,513B1740|118.116667,34.533333,580.6,港上,51101800|117.774111,34.130111,580.0,杨庙,512B9380|118.983972,35.020194,580.0,二龙山,513B1760|118.8625,34.758889,579.6,横沟水库,51115750|119.00225,35.046694,579.0,谢湖,513B1820|119.0095,35.050222,579.0,谭湖,513B1840|118.321833,34.204778,577.0,响水沟,511B8800|117.95,33.9,576.5,睢宁,50939900|119.502,31.1795,573.0,深溪介,63124100|118.931472,34.917083,572.0,夹沟,513B1940|119.044389,35.0445,571.0,石埠,513B1300|120.120556,33.398333,569.0,盐城,51010000|120.96098,31.379209,567.8,昆山,63205150|117.852278,34.074639,567.5,二堡,509B4480|118.972972,35.007722,566.5,大赤涧,513B1380|118.722811,34.63274,566.0,横沟,51133200|118.321583,34.210444,565.5,禅堂,511B8820|119.107193,31.308807,565.0,茅东闸,63101001|120.655932,31.199596,561.0,瓜泾口,63205400|119.713611,33.300833,560.8000000000001,黄土沟,51008000|117.95,34.01,560.0,魏集,50940100|119.5333,34.5,559.5,善后新闸,51126750|118.345083,34.211278,559.5,黄草关,511B8320|118.85,34.5333,557.5,麦坡,51133000|118.282917,34.204083,557.5,白龙马,511B8340|118.575972,34.629028,556.0,代相,511B7480|119.799722,33.469167,554.5999999999999,建湖,51008050|120.28347,31.560984,553.6000000000001,无锡（大）,63202851|118.573194,34.651778,553.5,高埝,511B7260|118.432694,34.584889,551.5,前贤,511B7100|118.75,34.25,551.0,贤官亭,51132500|117.730167,34.12775,551.0,锅山,511B8900|119.621389,33.309444,551.0,射阳镇,51008700|118.466667,34.216667,550.1999999999999,时集,51132300|118.64891,34.530029,550.0,贺庄水库,51115450|118.28,34.13,547.0,新店,51126150|118.509972,34.681222,546.0,邵家,511B7200|119.019472,35.0165,546.0,尖岭,513B1800|118.2945,34.225889,545.0,跃进,511B8740|121.5274,31.8479,544.0,新港,51030650|117.679944,34.506444,542.0,黄楼,512B9320|118.7667,34.5167,542.0,牛山,51133300|118.343611,34.193806,541.0,三仙洞,511B8640|116.916667,34.733333,540.4,沛城闸,51215101|119.3833,34.55,539.0,东辛农场,51127250|117.872314,34.072284,539.0,庆安,50915800|118.8667,33.4333,537.0,赵集,50941600|118.437,34.553167,536.5,官庄,511B7560|119.647778,33.446667,536.2,收成庄,51008800|119.299889,34.676722,536.0,新县,511B8180|118.554833,34.604472,534.0,北沟,511B7500|119.365778,34.707694,534.0,李庄,511B8120|119.372634,31.397552,533.5,大溪水库,63101401|120.731592,31.489065,533.0,湘城,63204650|120.560076,31.319474,533.0,苏州（枫桥）,63203000|118.62,34.23,532.5,阴平,51132450|119.297706,31.786742,532.5,南镇街,63127300|119.027767,34.585453,532.5,包庄,51133500|118.569694,34.704556,532.0,石寨,511B7180|118.470278,34.293194,531.5,砂墩,511B8560|118.556028,34.655528,531.5,场西,511B7280|118.732681,34.525222,531.3,西双湖水库,51115550|121.591658,32.04897,531.0,三和港北闸（闸上）,62712700|119.301944,34.682111,530.0,黄泥塘,511B8200|118.8566,32.0863,530.0,军民友谊水库,627B8100|119.8,31.366667,529.6,宜兴（西）,63101300|118.921472,34.826417,529.5,三里庙(1),513B2320|121.203832,31.607925,528.8000000000001,七浦闸(上),63204850|121.4115,32.0576,528.5,包场整编,51030150|120.442595,33.355595,528.4,斗龙,51028350|116.736722,34.487472,527.5,梁寨（2）,509B4100|121.7034,31.9857,527.5,七门闸整编,51031050|119.456717,33.637117,527.5,苏咀,51021600|118.4039,32.0392,526.5,蒋家坝堰水库,629B9040|117.83333,34.23333,525.5999999999999,刘集闸,51210551|118.05,34.18333,525.4,窑湾,51205400|118.470039,34.373195,524.0,高塘,51112650|117.36725,34.086083,523.0,伴山,509B4300|117.524185,34.15088,523.0,崔贺庄,51210570|118.4461,31.9828,523.0,三岔水库,62936750|118.452361,34.541333,522.0,皇城,511B7380|119.0661,31.3203,520.5,苗圃水库,629B8000|119.774476,34.24334,519.8,南河,51129100|119.711,31.1831,519.6,杨省庄,63125700|118.572778,34.656861,518.0,场东,511B7240|119.714,31.4998,517.6,官林,63125500|121.0445,31.9328,517.5,川港,51030450|118.6648,31.7871,517.5,牌坊水库,627B5800|120.2561,34.26806,516.0,翻身河闸,51001550|117.55,34.28,515.5,大许家,51228500|116.95,34.5,514.0,敬安集,51235000|119.397944,34.672083,514.0,云门,511B8240|118.9,34.6333,513.5,下河套,51133450|118.5244,32.0373,513.5,侯坝水库,627B7020|119.493913,31.426246,513.0,溧阳,63101200|119.0253,32.1101,513.0,周冲水库,627B8080|119.917831,31.797932,512.5,常州,63202750|118.435361,34.59775,512.0,后贤,511B7080|119.397778,33.376944,512.0,陆庄,51008600|117.5833,34.03333,510.5,双沟(徐),50938400|120.886946,31.182112,510.0,陈墓(锦溪),63403500|118.840656,34.369936,509.40000000000003,小许庄,51114300|118.7426,31.7348,509.0,前坎塘水库,627B6480|119.2333,33.65,509.0,钦工,51021550|118.673629,34.65891,508.90000000000003,羽山水库,51115810|117.777778,34.116889,507.0,清水畔（1）,511B8860|117.611222,34.477361,507.0,小吴,512B9340|118.864806,34.815861,506.5,群英,511B7020|118.5097,32.0821,506.5,唐冲水库,629B9180|119.655061,34.1217,506.00000000000006,小尖,51129050|117.498917,34.078694,506.0,吴湾(2),509B4360|116.736722,34.487472,506.0,梁寨（1）,509B4080|117.798974,33.763817,505.5,李集,50939000";
/*    	String pa = "requestJson={\"borderId\":\"320000\",\"edate\":\"201512188\",\"sdate\":\"201512178\",\"rainLevel\":\"A:10,25,50,100,150,200\",\"rainData\":\"118.303917,34.239278,0.5,高林（2),511B8520|119.397778,33.376944,0.5,陆庄,51008600|119.3206,32.5994,0.5,北涧水库,510B6460|118.316611,34.155167,0.5,蔡庄,511B8480|118.639972,32.7655,0.5,雨山水库,629B6120|119.352306,31.799139,0.5,杨兴洼水库,632B3440|118.40178,33.57217,0.5,丁岗水库,509B7080|118.5872,33.63189,0.5,小街,50916180|118.15053,33.98561,0.5,牛角闸,51215180|119.597972,32.131639,0.5,龙山水库（丹徒）,627B2360|118.8483,33.2017,0.5,东双沟,51021850|118.0158,33.277808,0.5,郑集,50927400|120.341667,32.833889,0.2,东台(泰),51006530|120.231884,33.949418,0.2,三区,51026850|118.696975,33.693695,0.2,泗阳闸,51206101|118.183333,33.45,0.2,泗洪(老),50914700|121.0172,31.54357,0.0,直塘,63204800|119.267583,31.541889,0.0,三百亩塘水库,632B5120|119.347278,31.647944,0.0,向阳水库,632B3060|118.8423,32.5608,0.0,吴庄水库,510B7060|119.0118,31.7183,0.0,东角塘水库,627B5140|118.8821,31.6501,0.0,独山水库,627B5480|118.6568,31.8328,0.0,高庄水库（江宁）,627B5740|118.8646,31.6664,0.0,回龙坳水库,627B6520|118.607,32.4881,0.0,红阳水库,627B7720|118.9546,31.2536,0.0,大花山水库,629B8060|119.0643,31.5075,0.0,山里沟水库,629B8400|118.9028,31.5749,0.0,焦赞石水库,629B8560|118.9913,31.6046,0.0,神山凹水库,629B8800|118.603444,34.615667,0.0,官庄,511B7400|118.437,34.553167,0.0,官庄,511B7560|119.195861,35.043139,0.0,白石头,513B1280|119.527,33.144,0.0,芦范,51005120|119.311,32.291,0.0,朴席,51005480|119.255,32.435,0.0,刘集,51023800|119.1483,32.2664,0.0,铜山,51005125|118.116667,34.533333,0.0,港上,51101800|117.83333,34.23333,0.0,刘集闸,51210551|117.265361,34.204389,0.0,大龙口（1）,509B4000|117.36725,34.086083,0.0,伴山,509B4300|117.402944,34.187306,0.0,白桥,509B4320|118.454556,34.331667,0.0,石涧,511B8440|118.284222,34.276194,0.0,小冲,511B8700|118.318028,34.179389,0.0,曹刘,511B8780|118.317389,34.194333,0.0,李坎沟,511B8840|117.363333,34.454917,0.0,雷鼓山,512B9080|117.453583,34.227222,0.0,五孔桥,512B9280|117.747764,33.994851,0.0,大王集,50938600|116.46,34.74,0.0,赵庄,51214700|119.456717,33.637117,0.0,苏咀,51021600|120.392778,33.726944,0.0,利民河闸,51009750|120.691111,33.186667,0.0,王港新闸,51010800|120.903611,32.871667,0.0,梁垛河闸,51010420|119.009737,31.739377,0.0,夏家边,63128800|118.922593,31.773045,0.0,艾园,63128900|118.912521,32.046631,0.0,其林,63129500|119.0578,32.0878,0.0,安基山,62727700|119.0639,31.5824,0.0,王家甸水库,627B5000|119.1831,31.6485,0.0,友谊水库（溧水）,627B5380|118.816389,32.953833,0.0,胜利水库,509B5320|118.5167,32.8333,0.0,山洪,50928101|118.7273,31.881,0.0,竹塘水库,627B6020|118.6614,32.1239,0.0,珍珠泉水库,627B7180|118.7854,32.5271,0.0,何营水库,627B7560|118.7445,32.4389,0.0,傅湾水库,627B7660|118.5816,32.5707,0.0,彭家港水库,627B7940|119.1045,31.3769,0.0,大新塘水库,631B1020|119.186944,31.503,0.0,鸡隆坝水库,632B4660|119.258222,31.6175,0.0,子儒桥水库,632B5220|119.25,31.55,0.0,东岳庙,63121900|119.08639,34.12317,0.0,柴南,51106180|118.4,33.72,0.0,屠园,50941200|118.261,33.369,0.0,石集,50941620|118.85,34.3,0.0,朱贵庄,51126900|119,34.116,0.0,汤涧,51127460|118.736,33.851,0.0,王集(宿迁),51128120|118.47039,33.63222,0.0,西便河闸,51205475|118.19806,33.59281,0.0,梅东水库,509B7180|118.00636,33.24331,0.0,邵庄水库,509B7540|118.878139,34.922889,0.0,夹谷山,513B2060|118.570694,34.532778,0.0,阳春(2),511B7650|118.983444,34.9885,0.0,车赤涧,513B1680|118.796944,32.016111,0.0,武定门闸,62702451|119.2922,32.4761,0.0,梅桥水库,510B6240|119.2346,32.5263,0.0,迎丰水库,510B6340\"}";
*/        
    	String s=HttpRequest.sendPost(url,pa);
    	String dzx=s.substring(s.indexOf("<dzx>")+5, s.indexOf("</dzx>"));
    	String dzm=s.substring(s.indexOf("<dzm>")+5, s.indexOf("</dzm>"));
        System.out.println(s);
        System.out.println(dzx);
        System.out.println(dzm);
	}

}
